/**
 * Main-action to display the basic frontpage
 */
Root.prototype.main_action = function() {
    res.data.title = "Welcome!";
    res.data.body = this.renderSkinAsString("welcome");
    renderSkin("main");
    return;
}

/**
 * Adds a new Hyperlink to the Root-HopObject. Checks the required
 * POST-param longurl if it's really an URL.
 */
Root.prototype.add_action = function() {
    // Check the request
    if (req.isPost()) {
        if (req.postParams["longurl"] && req.postParams["longurl"].isUrl()) {
            // create new Hyperlink object
            var link = new Hyperlink(req.postParams.longurl, req.postParams.title);
            this.add(link);
            res.redirect(link.href("preview"));
        } else {
            res.write("Invalid URL!");
        }
    } else {
        res.write("Invalid request!");
    }
    return;
}

/**
 * Renders a list of all links.
 */
Root.prototype.overview_action = function() {
    // Setting up a new ListRenderer which displays
    // a maximum of 500 links.
    var list = res.handlers.list = new jala.ListRenderer(root);
    list.setPageSize(5);
    list.setMaxPages(50);
    res.data.body = this.renderSkinAsString("overview");
    
    renderSkin("main");
    return;
}